package com.bonc.event.extractor;

import java.util.Set;

//import org.apache.clerezza.rdf.core.UriRef;
//import org.apache.stanbol.enhancer.nlp.dependency.GrammaticalRelation;

/**
 * A thematic relation which can be part of a {@link Rule} definition. Defines a
 * participant (agent, patient..etc) in an event.
 * 
 * @author Cristian Petroaca
 *
 */
public class ThematicRelation {
	/**
	 * Type
	 */
	private ThematicRelationType type;

	/**
	 * The set of entity types (defined as UriRefs contained in an RDF_TYPE
	 * property of an {@link Entity} in a Stanbol Site) which the {@link Entity}
	 * needs to have in order for it to be catalogued as this thematic relation.
	 */
//	private Set<UriRef> entityTypes;
	private Set<String> entityTypes;

	/**
	 * The {@link GrammaticalRelation} that the identified text span needs to
	 * have in order to be catalogued as this thematic relation.
	 */
//	private GrammaticalRelation grammaticalRelation;
	private String grammaticalRelation;

	/**
	 * If this thematic relation is mandatory to be found in a given event.
	 */
	private boolean isMandatory;

	public ThematicRelation(ThematicRelationType type, Set<String> entityTypes, String grammaticalRelation,
			boolean isMandatory) {
		if (type == null) {
			throw new IllegalArgumentException("thematic relation type must not be null");
		}

		if (entityTypes == null || entityTypes.isEmpty()) {
			throw new IllegalArgumentException("entityTypes must not be null or empty");
		}

		if (grammaticalRelation == null) {
			throw new IllegalArgumentException("grammaticalRelation must not be null");
		}

		this.type = type;
		this.entityTypes = entityTypes;
		this.grammaticalRelation = grammaticalRelation;
		this.isMandatory = isMandatory;
	}

	public ThematicRelationType getType() {
		return type;
	}

	public Set<String> getEntityTypes() {
		return entityTypes;
	}

	public String getGrammaticalRelation() {
		return grammaticalRelation;
	}

	public boolean isMandatory() {
		return isMandatory;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + type.hashCode();
		result = prime * result + entityTypes.hashCode();
		result = prime * result + grammaticalRelation.hashCode();
		result = prime * result + (isMandatory ? 1231 : 1237);

		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;

		ThematicRelation other = (ThematicRelation) obj;

		return type.equals(other.type) && entityTypes.equals(other.entityTypes)
				&& grammaticalRelation.equals(other.grammaticalRelation) && isMandatory == other.isMandatory;
	}
}
